/* 
 * File:   MPriorityList.c
 * Author: Muqtafi Akhmad
 */

#include <stdio.h>
#include <stdlib.h>
#include "PriorityList.h"

int main(int argc, char** argv) {
    // Kamus
    long eventNo = 100;
    DateTime dateTime = MakeDateTime(2012, 10, 20, 20, 0, 0);
    Point position = MakePoint(11.00, 12.00);
    char description[EVENT_DESCRIPTION_MAX_LENGTH] = "Acara Syukuran Wisuda Oktober 2012";
    char** participants;
    participants = (char**) malloc(2 * sizeof (char*));
    participants[0] = (char*) malloc(PARTICIPANT_NAME_MAX_LENGTH * sizeof (char));
    participants[1] = (char*) malloc(PARTICIPANT_NAME_MAX_LENGTH * sizeof (char));
    short int participantCount = 2;
    EventList list;

    // Algoritma
    strcpy(participants[0], "Participant A");
    strcpy(participants[1], "Participant B");
    CreateEventList(&list);

    printf("# insert event pertama \n");
    // 2012-10-20 20:00:00
    Event event1 = MakeEvent(eventNo, dateTime, position, description, participants, participantCount);
    // PrintEvent(event1);
    InsertEvent(&list, event1);

    printf("# insert event kedua \n");
    // 2013-10-20 20:00:00
    dateTime.D.year = 2013;
    eventNo = 101;
    Event event2 = MakeEvent(eventNo, dateTime, position, description, participants, participantCount);
    // PrintEvent(event2);
    InsertEvent(&list, event2);


    printf("# insert event ketiga \n");
    // 2012-09-20 20:00:00
    dateTime.D.year = 2012;
    dateTime.D.month = 9;
    eventNo = 102;
    Event event3 = MakeEvent(eventNo, dateTime, position, description, participants, participantCount);
    // PrintEvent(event3);
    InsertEvent(&list, event3);

    printf("# insert event keempat \n");
    // 2012-09-19 20:00:00
    dateTime.D.day = 19;
    eventNo = 103;
    Event event4 = MakeEvent(eventNo, dateTime, position, description, participants, participantCount);
    // PrintEvent(event4);
    InsertEvent(&list, event4);

    printf("# insert event kelima \n");
    // 2012-09-19 22:00:00
    dateTime.T.H = 22;
    eventNo = 104;
    Event event5 = MakeEvent(eventNo, dateTime, position, description, participants, participantCount);
    // PrintEvent(event4);
    InsertEvent(&list, event5);
    printf("## \n");
    printf("## Complete List \n");
    printf("## \n");
    PrintInfo(list);
    printf("## \n");
    printf("## Last 3 Elements \n");
    printf("## \n");
    EventAddr addr = GetLastNAddress(list, 3);
    while (addr != NULL) {
        PrintEvent(Info(addr));
        addr = Next(addr);
    }

    DeleteEvent(&list, 101);
    DeleteEvent(&list, 103);
    printf("## \n");
    printf("## List After Some Elements Deleted \n");
    printf("## \n");
    PrintInfo(list);

    long entryNoBuff[100];
    int count = GetEventCountInDay(list, dateTime, entryNoBuff, 100), iter;
    if (count > 0) {
        printf("Found some events : \n");
        for (iter = 0; iter < count; iter++) {
            printf("    Entry no : %ld \n", entryNoBuff[iter]);
        }
    } else {
        printf("Can't find event");
    }
    Dealokasi(&list);
    printf("%ld, %ld \n", First(list), Last(list));

    return (EXIT_SUCCESS);
}

